package sz.szsmk.citizencard.ui.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.seapeak.recyclebundle.BaseHolder;
import com.seapeak.recyclebundle.BaseRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.BusLineItemBinding;
import sz.szsmk.citizencard.model.network.bean.response.QueryBusLineNearbyRes;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/11/15 14:44
 * description:
 */
public class BusLineAdapter extends BaseRecyclerAdapter<BusLineAdapter.BusLineHolder> {
    private FragmentActivity mContext;
    private List<QueryBusLineNearbyRes.BusLineArrayListBean.BusLineListBean> viewData = new ArrayList<>();

    private BaseInterface baseInterface;

    public interface BaseInterface {
        public void onClick(View view, int position);
    }

    public void setBaseInterface(BaseInterface baseInterface) {
        this.baseInterface = baseInterface;
    }


    public BusLineAdapter(FragmentActivity mContext) {
        this.mContext = mContext;

    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.bus_line_item;
    }

    @Override
    public BusLineHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return BusLineHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(BusLineHolder holder, int position) {
        loadItemData(position, holder.binding);
    }

    private void loadItemData(final int position, BusLineItemBinding binding) {
        binding.lineEnd.setText(viewData.get(position).getLine_direction());
//        binding.lineNum.setText(viewData.get(position).getStand_count());
        binding.lineAdress.setText("米，位于" + (String.valueOf(viewData.get(position).getLand_load())));
//        binding.lineDes.setText("后到达，位于"+viewData.get(position).getLand_load());


        binding.busLineRl.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {

                if (baseInterface != null) {
                    baseInterface.onClick(null, position);
                }
//                Bundle bundle = new Bundle();
//                String line_guid = viewData.get(position).getLine_guid();
//                bundle.putString("line_guid", line_guid);
//                String line_name = viewData.get(position).getLine_name();
//
//                bundle.putString("line_name", line_name);
//                JumpUtils.jumptoNatvie(mContext, "RealTimeLineActivity", 0,bundle);
//                Intent i1 = new Intent();

//                i1.setData(Uri.parse("androidamap://bus?sourceApplication=softname&busname=303&city=025"));
                //百度地图
//                i1.setData(Uri.parse("baidumap://map/line?region=南京&name=303&src=andr.baidu.openAPIdemo"));
//                mContext.startActivity(i1);
//                startActivity(i1);

            }
        });
    }


    @Override
    public int getItemCount() {
        return null == viewData ? 0 : viewData.size();
    }

    public void setViewData(List<QueryBusLineNearbyRes.BusLineArrayListBean.BusLineListBean> viewData) {
        if (viewData != null && viewData.size() > 0) {
            this.viewData.clear();
            this.viewData.addAll(viewData);
            notifyDataSetChanged();
        }
    }

    public static class BusLineHolder extends BaseHolder {
        private BusLineItemBinding binding;

        public static BusLineHolder creat(ViewGroup parent) {
            BusLineItemBinding binding = BusLineItemBinding
                    .inflate(LayoutInflater.from(parent.getContext()), parent, false);

            return new BusLineHolder(binding);
        }

        public BusLineHolder(BusLineItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
